package nf.model;

import java.io.Serializable;

import java.sql.Timestamp;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@NamedQueries( { @NamedQuery(name = "Tasks.findAll",
                             query = "select o from Tasks o"),
                 @NamedQuery(name = "Tasks.findByParent",
                             query = "select o from Tasks o where o.parentTaskId = :p_parent_task") })

@Table(name = "\"Tasks\"")
@SequenceGenerator(name = "TasksSeq", sequenceName = "TasksSeq")
public class Tasks implements Serializable {
    @Column(name = "Created", nullable = false)
    private Timestamp created;
    //    @Column(name="Creator", nullable = false)
    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "Creator", nullable = false)
    private Subject creator;
    @Column(name = "Description")
    private String description;
    @Column(name = "Executor")
    private Long executor;
    @Column(name = "FactEnd")
    private Timestamp factEnd;
    @Column(name = "FactStart")
    private Timestamp factStart;
    @Id
    @Column(name = "Id", nullable = false)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN")
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TasksSeq")
  private Long id;
    @Column(name = "Name", nullable = false)
    private String name;
    /*@Column(name="Owner")
    private Long owner;*/
    @Column(name = "PlanEnd")
    private Timestamp planEnd;
    @Column(name = "PlanStart")
    private Timestamp planStart;

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "ParentTaskId")
    private Tasks parentTaskId;

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "Owner")
    private Subject owner;

    public Tasks() {
        this.created = new Timestamp(System.currentTimeMillis());
    }

    public Tasks(Subject creator, String description, Long executor,
                 Timestamp factEnd, Timestamp factStart, Long id, String name,
                 Subject owner, Tasks parentTaskId, Timestamp planEnd,
                 Timestamp planStart) {
        this.created = new Timestamp(System.currentTimeMillis());
        this.creator = creator;
        this.description = description;
        this.executor = executor;
        this.factEnd = factEnd;
        this.factStart = factStart;
        this.id = id;
        this.name = name;
        this.owner = owner;
        this.parentTaskId = parentTaskId;
        this.planEnd = planEnd;
        this.planStart = planStart;
    }

    public Timestamp getCreated() {
        return created;
    }

    public void setCreated(Timestamp created) {
        this.created = created;
    }

    public Subject getCreator() {
        return creator;
    }

    public void setCreator(Subject creator) {
        this.creator = creator;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getExecutor() {
        return executor;
    }

    public void setExecutor(Long executor) {
        this.executor = executor;
    }

    public Timestamp getFactEnd() {
        return factEnd;
    }

    public void setFactEnd(Timestamp factEnd) {
        this.factEnd = factEnd;
    }

    public Timestamp getFactStart() {
        return factStart;
    }

    public void setFactStart(Timestamp factStart) {
        this.factStart = factStart;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /*    public Long getOwner() {
        return owner;
    }

    public void setOwner(Long owner) {
        this.owner = owner;
    }
*/

    public Timestamp getPlanEnd() {
        return planEnd;
    }

    public void setPlanEnd(Timestamp planEnd) {
        this.planEnd = planEnd;
    }

    public Timestamp getPlanStart() {
        return planStart;
    }

    public void setPlanStart(Timestamp planStart) {
        this.planStart = planStart;
    }

    public Tasks getParentTaskId() {
        return parentTaskId;
    }

    public void setParentTaskId(Tasks parentTaskId) {
        this.parentTaskId = parentTaskId;
    }

    public Subject getOwner() {
        return owner;
    }

    public void setOwner(Subject owner) {
        this.owner = owner;
    }
}
